package com.zw.pdm.module.est.service;

import com.zw.pdm.entity.est.Card;
import com.zw.pdm.entity.est.CardChange;
import com.zw.pdm.entity.est.CardDetail;
import com.zw.pdm.entity.est.CardDetailChange;
import com.zw.pdm.module.est.mapper.CardMapper;
import com.zw.pdm.module.est.model.CardList;
import com.zw.pdm.module.est.repository.CardRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description:
 *
 * @Author: China.sgl
 * @Date: 2019/12/6 08:42
 */
@Service
@SuppressWarnings("all")
public class CardChangeQueryService {

    @Autowired
    private CardMapper cardMapper;
    @Autowired
    private CardRepository cardRepository;

    /** 列表 */
    public List<Card> findWithCardChangeQuery(Card card) {
        return cardMapper.findWithCardChangeQuery(card);
    }

    public Card getCardById(Integer id) {
        return cardRepository.getOne(id);
    }

    public CardChange getTopChangeCardByCardId(Integer id) {
        return cardMapper.getTopChangeCardByCardId(id);
    }

    public List<CardDetailChange> findCardChangeDetailByChangeCardId(Integer id) {
        return cardMapper.findCardChangeDetailByChangeCardId(id);
    }

    public List<CardDetail> findCardDetailByCardId(Integer id) {
        return cardMapper.findDetailByCardId(id);
    }

    public List<CardList> findCardChangeListByCardId(Integer id) {
        List<CardList> list = new ArrayList<>();
        List<CardChange> cardChanges = cardMapper.findCardchangeByCardId(id);
        for (CardChange cardChange : cardChanges) {
            CardList cl = new CardList();
            cl.setCardChange(cardChange);
            cl.setCardChangeDetaillist(cardMapper.findCardChangeDetailByChangeCardId(cardChange.getId()));
            list.add(cl);
        }
        return list;
    }
}
